<template>
  <div class="app-container">
    <el-form      :model="queryParams"      ref="queryForm"      size="small"      :inline="true"      v-show="showSearch"      label-width="68px"    >
      <el-form-item label="检索" prop="search">
        <el-input v-model="queryParams.search" placeholder="请输入检索信息" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="领料单号" prop="search">
        <el-input
          v-model="queryParams.OrderId"
          placeholder="请输入领料单号"
          clearable          
        />
      </el-form-item> -->
      <!-- @keyup.enter.native="handleQuery" -->
      <el-form-item label="日期" prop="providerId">
        <el-date-picker
          clearable
          v-model="queryParams.dateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>  <br/>
      <el-form-item label="申请状态" prop="createStatus">
        <el-select
          v-model="queryParams.createStatus"
          placeholder="请选择申请状态"
        >
          <el-option label="待审核" value="0"></el-option>
          <el-option label="已审核" value="1"></el-option>
          <el-option label="未提交" value="2"></el-option>
        </el-select>
      </el-form-item>
       <el-form-item label="审核状态" prop="updateStatus">
        <el-select
          v-model="queryParams.updateStatus"
          placeholder="请选择审核状态"
        >
          <el-option label="驳回" value="0"></el-option>
          <el-option label="审核通过" value="1"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="SearchList"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="GrainList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="50" label="编号" />
      <el-table-column label="领料单号" align="center" prop="orderId" />
      <el-table-column label="生产计划" align="center" prop="proPlan" />
      <el-table-column label="计划排产" align="center" prop="proNum" />
      <el-table-column label="产品" align="center" prop="product" />
      <el-table-column label="型号" align="center" prop="proModel" />
      <el-table-column label="规格" align="center" prop="proSpe" />
      <el-table-column label="单位" align="center" prop="proUnit" />
      <el-table-column label="领取日期" align="center" prop="getTime" />
      <el-table-column label="申请人" align="center" prop="proposer" />
      <el-table-column label="申请日期" align="center" prop="reqTime" />
      <el-table-column label="申请状态" align="center" prop="reqStatus">
        <template slot-scope="scope">
          <el-tag effect="dark" type="danger" v-if="scope.row.reqStatus == '0'">
            待审核
          </el-tag>
          <el-tag effect="dark" type="info" v-else-if="scope.row.reqStatus == '1'">
            已审核
          </el-tag>
          <el-tag effect="dark" type="success" v-else> 未提交 </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditor" />
      <el-table-column label="审核日期" align="center" prop="audTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.audTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="audStatus">
        <template slot-scope="scope">
          <el-tag   effect="dark"            type="danger"            v-if="scope.row.audStatus == '0'"          >
            驳回
          </el-tag>
          <el-tag    effect="dark"            type="info"            v-else-if="scope.row.audStatus == '1'"          >
            审核通过
          </el-tag>
          <el-tag effect="dark" v-else> 待审核 </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['carbon:Grain:edit']"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination v-show="total > 0" :total="total"   :page.sync="queryParams.pageNum"  :limit.sync="queryParams.pageSize"  @pagination="getList"    /> -->

    <!-- 详情信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-form-item label="审核意见" prop="businessId">
          <el-select  v-model="form.aud_status"     placeholder="请选择"    :disabled="this.type == '12'" >
            <el-option label="驳回" :value="'0'"></el-option>
            <el-option label="通过" :value="'1'"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="success" @click="submitForm1" v-if="this.type != '12'">保 存</el-button> -->
        <el-button type="primary" @click="submitForm" v-if="this.type != '12'"
          >提 交</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  changeGrainStatus,
  list,
  getGrain,
  Search,
  updateAudit,
} from "@/api/wms/material";
export default {
  name: "Grain",
  data() {
    return {
      // 情况 123
      type: "0",
      // 生产厂家
      productList: [],
      props1: {
        value: "id",
        label: "name",
        children: "children",
      },
      //仓库
      wareList: [],
      props: {
        value: "id",
        label: "wareName",
        children: "children",
      },
      // 供应商
      providerList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库信息表格数据
      GrainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        // 单据状态
        orderStatus: "0",
        // 入库状态
        status: "0",
        // 申请状态
        createStatus: "0",
        // 审核状态
        updateStatus: "0",
      },
    };
  },
  created() {
    this.getList();
    // this.getproviderList();
    // this.getProductTreeList();
    // this.getWareList();
  },
  methods: {
    // 获取生产单位树形结构
    // getProductTreeList() {
    //   getProductTreeNode().then((res) => {
    //     this.productList = res.data;
    //   });
    // },
    // 格式化数据，递归将空的children置为undefined
    // formatData(data) {
    //   for (var i = 0; i < data.length; i++) {
    //     if (data[i].children.length < 1) {
    //       // children若为空数组，则将children设为undefined
    //       data[i].children = undefined;
    //     } else {
    //       // children若不为空数组，则继续 递归调用 本方法
    //       this.formatData(data[i].children);
    //     }
    //   }
    //   return data;
    // },
    // 审核
    handleUpdateStatus(row) {
      changeGrainStatus(row.id).then((res) => {
        this.$message.success("入库成功");
        this.getList();
      });
    },
/** 搜索按钮操作 */
    SearchList() {
    //   this.queryParams.pageNum = 1;
    //   this.form=this.queryParams;
    //   console.log(this.form);
      Search(this.queryParams).then((response) => {
            this.$modal.msgSuccess(response.msg);
            this.open = false;
            // this.reset();
            console.log(response);
            this.GrainList = response.data;
          });
    //   this.getList();
    },
    /** 查询入库信息列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        this.GrainList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.type = "0";
      this.form = {
        createStatus: null,
      };
      this.resetForm("form");
    },
    
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.resetForm("queryForm");
    //   this.handleQuery();
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.getProductTreeList();
    //   this.getWareList();
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加入库信息";
    // },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      if (row.createStatus != "2") {
        this.type = "123";
      } else {
        this.type = "4";
      }
      getGrain(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改入库信息";
      });
    },
    getCurrentTime() {
      //获取当前时间并打印
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      this.form.audTime =
        yy + "/" + mm + "/" + dd + " " + hh + ":" + mf + ":" + ss;
    },  
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.aud_status == "1") {
            this.form.audStatus = "1";
          } else {
            this.form.audStatus = "0";
          }
          
          this.getCurrentTime();
          updateAudit(this.form).then((response) => {
            this.$modal.msgSuccess(response.msg);
            this.open = false;
            this.reset();
            console.log(this.form);
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$modal
    //     .confirm('是否确认删除入库信息编号为"' + ids + '"的数据项？')
    //     .then(function () {
    //       return delGrain(ids);
    //     })
    //     .then(() => {
    //       this.getList();
    //       this.$modal.msgSuccess("删除成功");
    //     })
    //     .catch(() => {});
    // },
  },
};
</script>
  